<?
layout("/inc/win_layout.html",{title:sysTitle}){}
    ?>

<div class="page-content">
		<table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th>序号</th>
					<th>版本号</th>
					<th>修改时间</th>
					<th>修改者</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="findUser">
			
			</tbody>
		</table>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	</div>
<script type="text/javascript">
	var knowledgeVersionsId = window.parent.getKnowledgeVersionsId();
	var classesEn = window.parent.getclassesEn();
	var ye = window.parent.getYe();
	var buttonType = window.parent.getButtonType();
	var curr;
	
	$(function()  {
		queryknowledgeVersions(curr);
	});
	function queryknowledgeVersions(curr){
		$.ajax({
			type : "post",
			url : "queryknowledgeVersions.do",
			dataType : "json",
			data :{
				"knowledgeVersionsId" : knowledgeVersionsId,
				"classesEn" : classesEn,
				"curr" : curr || 1,
			},
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(res){
				//alert(JSON.stringify(res));
				 var str = "";
				for ( var i = 0; i < res[0].data.length; i++) {
					str += "<tr><td>" 
							+(i + 1)
							+ "</td><td>"
							+ res[0].data[i].version
							+ "</td><td>"
							+ res[0].data[i].update_time
							+ "</td><td>"
							+ res[0].data[i].update_user_id
							/* + "</td><td>"
							+ res[0].data[i].date
							+ "</td><td>"
							+ res[0].data[i].version */
							+ "</td><td>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"queryVersionsHistory('"+res[0].data[i].classes_id+ "','"+res[0].data[i].id+ "')\">"
							+ "查看详情"
							+ "</button>&nbsp;&nbsp;&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"knowledgeVersionsRestore('"+res[0].data[i].classes_id+ "','"+res[0].data[i].id+ "','"+res[0].data[i].source_data_id+ "')\">"
							+ "恢复该版本"
							+ "</button>"
							+ "</td>"
							+ "</tr>";
				}
				$("#findUser").html(str);
					laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res[0].page, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: curr || 1,
					last: res[0].page,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							queryknowledgeVersions(obj.curr);
							 curr = obj.curr;
						}
					}
				}); 
			}
		});
	
	}
	//查看详情
	function queryVersionsHistory(versionsClassesId,VersionsDetailsId){
		window.open("queryknowledgeVersionsDetails?classesId="+versionsClassesId+"&id="+VersionsDetailsId);
	}
	//恢复版本
	function knowledgeVersionsRestore(versionsClassesId,VersionsDetailsId,knowledgeId){
		$.ajax({
			type : "post",
			url : "knowledgeVersionsRestore.do",
			dataType : "json",
			data :{
				"versionsClassesId" : versionsClassesId,
				"VersionsDetailsId" : VersionsDetailsId,
				"knowledgeId" : knowledgeId,
			},
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(res){
				if(res[0].data == 'yes'){
					var index = parent.layer.getFrameIndex(window.name); 
	           		 window.parent.demo1(ye,buttonType);
	           		 parent.layer.msg('恢复成功');
	            	 parent.layer.close(index); 
				}else{
					 parent.layer.msg('恢复失败！请联系管理员');
				}
				//alert(JSON.stringify(res));
			}
		});
	
	}
</script>
